//
// Created by 10462397 on 2021/9/9.
//

#include "../../common.h"

class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {

        vector<int> res{};
        int c = 1;
        for (int i = digits.size() - 1; i > -1; --i) {
            c += digits[i];
            if (c > 9) {
                res.emplace_back(c - 10);
                c = 1;
            } else {
                res.emplace_back(c);
                c = 0;
            }
        }
        if (c > 0) {
            res.emplace_back(c);
        }
        reverse(res.begin(), res.end());
        return res;
    }
};

int main() {

    vector<int> v{9,9,9};
    auto res = Solution().plusOne(v);
    for (const auto &item : res){
        cout << item << endl;
    }

}